package com.lyp.activitys;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lyp.jsonbean.IndoorDetailsBean;
import com.lyp.jsonbean.YesOrderBean;
import com.tjl.yangxixis.R;
import com.tjl.yangxixis.api.YangxixiApi;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class IndoorYiyuyueActivity extends Activity implements View.OnClickListener {

    private YesOrderBean.DataBean mBean;
    private List<IndoorDetailsBean.DataBean> mList = new ArrayList<>();
    private TextView mName, mPhone, mAddress, mDianwei, mMianji, mOrder, mTime;
    private ImageView mBack;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indoor);
        init();
    }

    private void init() {
        mBean = (YesOrderBean.DataBean) getIntent().getExtras().get("databean");
        mBack =(ImageView) findViewById(R.id.indoorback);
        mName = (TextView) findViewById(R.id.indoorname);
        mPhone = (TextView) findViewById(R.id.indoorphone);
        mAddress= (TextView) findViewById(R.id.indooraddress);
        mDianwei = (TextView) findViewById(R.id.indoordianwei);
        mMianji = (TextView) findViewById(R.id.indoormianji);
        mOrder = (TextView) findViewById(R.id.indoortime);
        mTime = (TextView) findViewById(R.id.indoornumber);

        mBack.setOnClickListener(this);

        try {
            indoor(mBean.getO_id());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //室内任务详情
    public void indoor(String o_id) throws IOException {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(YangxixiApi.APP_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        YangxixiApi api = retrofit.create(YangxixiApi.class);
        Call<IndoorDetailsBean> call = api.getIndoorOrders(o_id);
        call.enqueue(new Callback<IndoorDetailsBean>() {
            @Override
            public void onResponse(Call<IndoorDetailsBean> call, final Response<IndoorDetailsBean> response) {
                if (response.body().getResult() == 1 ) {
                    IndoorYiyuyueActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mList.addAll(response.body().getData());
                            mName.setText(mList.get(0).getUser_name());
                            mPhone.setText(mList.get(0).getU_phone());
                            mAddress.setText(mList.get(0).getU_addres());
                            mDianwei.setText(mList.get(0).getPoint_position());
                            mMianji.setText(mList.get(0).getCovered_area());
                            mOrder.setText(mList.get(0).getOrder_number());
                            mTime.setText(mList.get(0).getPay_time());

                        }
                    });
                }
                else {
                    ToastUtils.showShort(response.body().getMessage());
                }
            }
            @Override
            public void onFailure(Call<IndoorDetailsBean> call, Throwable t) {
                LogUtils.i("tag","失败"+t.getMessage());
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.indoorback:
                finish();
                break;
        }
    }
}